home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / Information / CSMP Digest / volume 1 / csmp-v1-191.txt < prev    next >
Encoding:
Text File  |  1994-12-08  |  43.2 KB  |  1,309 lines  |  [TEXT/R*ch]

  1. C.S.M.P. Digest             Tue, 20 Oct 92       Volume 1 : Issue 191
  2.  
  3. Today's Topics:
  4.  
  5.     Calling a resource as code?
  6.     Creating a floating palette in MacApp
  7.     Access to Map cdev data
  8.     Slaughtering Lambs in the Name of Jim Reekes
  9.     Setting the volume
  10.     I need a *fast* rand () procedure
  11.     MacTCP: can't send very many single bytes in a row
  12.     AppleEvent passing address
  13.     THINK Pascal v4.01 and 32-bit
  14.  
  15.  
  16.  
  17. The Comp.Sys.Mac.Programmer Digest is moderated by Michael A. Kelly.
  18.  
  19. The digest is a collection of article threads from the internet newsgroup
  20. comp.sys.mac.programmer.  It is designed for people who read c.s.m.p. semi-
  21. regularly and want an archive of the discussions.  If you don't know what a
  22. newsgroup is, you probably don't have access to it.  Ask your systems
  23. administrator(s) for details.  (This means you can't post questions to the
  24. digest.)
  25.  
  26. Each issue of the digest contains one or more sets of articles (called
  27. threads), with each set corresponding to a 'discussion' of a particular
  28. subject.  The articles are not edited; all articles included in this digest
  29. are in their original posted form (as received by our news server at
  30. cs.uoregon.edu).  Article threads are not added to the digest until the last
  31. article added to the thread is at least one month old (this is to ensure that
  32. the thread is dead before adding it to the digest).  Article threads that
  33. consist of only one message are generally not included in the digest.
  34.  
  35. The entire digest is available for anonymous ftp from ftp.cs.uoregon.edu
  36. [128.223.8.8] in the directory /pub/mac/csmp-digest.  Be sure to read the
  37. file /pub/mac/csmp-digest/README before downloading any files.  The most
  38. recent issues are available from sumex-aim.stanford.edu [36.44.0.6] in the
  39. directory /info-mac/digest/csmp.  If you don't have ftp capability, the sumex
  40. archive has a mail server; send a message with the text '$MACarch help' (no
  41. quotes) to LISTSERV@ricevm1.rice.edu for more information.
  42.  
  43. The digest is also available via email.  Just send a note saying that you
  44. want to be on the digest mailing list to mkelly@cs.uoregon.edu, and you will
  45. automatically receive each new issue as it is created.  Sorry, back issues
  46. are not available through the mailing list.
  47.  
  48. Send administrative mail to mkelly@cs.uoregon.edu.
  49.  
  50.  
  51. -------------------------------------------------------
  52.  
  53. From: clas005@csc.canterbury.ac.nz
  54. Subject: Calling a resource as code?
  55. Date: 4 Aug 92 14:27:15 +1200
  56. Organization: University of Canterbury, Christchurch, New Zealand
  57.  
  58. In Dave Mark's C Mac Programming Primer, an example is given of 
  59. how to write an INIT/CDEV where he loads a resource (of type 
  60. PROC, but this is not important) and calls it as executable code 
  61. by using CallPascal(), handing off a pointer to the resource.
  62.  
  63. My question is, how would I do this from within Pascal, 
  64. specifically from within THINK Pascal? How can I force a resource 
  65. to be regarded as code, and executed as a callable procedure?
  66.  
  67. - ----- matt = CLAS005@csc.canterbury.ac.nz
  68.  
  69. +++++++++++++++++++++++++++
  70.  
  71. From: Roger.W.Brown@dartmouth.edu (Roger W. Brown)
  72. Date: 4 Aug 92 14:54:09 GMT
  73. Organization: Dartmouth College, Hanover, NH
  74.  
  75. In article <1992Aug4.142715.148@csc.canterbury.ac.nz>
  76. clas005@csc.canterbury.ac.nz writes:
  77.  
  78. > My question is, how would I do this from within Pascal, 
  79. > specifically from within THINK Pascal? How can I force a resource 
  80. > to be regarded as code, and executed as a callable procedure?
  81.  
  82. This is how we do it in MPW. I don't know if it will be the same in
  83. Think Pascal.
  84.  
  85. Define an stub interface to the procedure with the proper parameters if
  86. there are any. This will be used to jump into the CODE using the inline
  87. statement.
  88.  
  89. ex. FUNCTION MyExternalFunction(var s1,s2,s3: Str255; addr:
  90. ProcPtr):Boolean;
  91.     inline
  92.         $205F, $4E90;
  93.  
  94. Get the resource, using its stripped address as the "addr" parameter:
  95.  
  96. ex.     {Get the function CODE module}
  97.  
  98.      {h is a Handle, kCodeID is a constant defining the resource ID, 
  99.       NoCodeError is an error number constant.}
  100.          h := GetResource('CODE', kCodeID);
  101.          if (h = nil) 
  102.                then Failure(NoCodeError,0);
  103.          DetachResource(h);
  104.  
  105.         {Call the function module and return the result}
  106.         HLock(h);
  107.  
  108.         functionResult :=
  109. MyExternalFunction(str1,str2,str3,StripAddress(h^));
  110.     
  111.      {Clean up}
  112.         DisposHandle(h);
  113.  
  114.  
  115.  
  116. - -----------------------------------------------------------------
  117. Roger Brown                           Roger.W.Brown@dartmouth.edu
  118. Software Development
  119. Kiewit Computation Center
  120. Dartmouth College, Hanover, NH
  121.  
  122. ---------------------------
  123.  
  124. From: poon@parc.xerox.com (Alex Poon)
  125. Subject: Creating a floating palette in MacApp
  126. Organization: Xerox PARC
  127. Date: 22 Jul 92 21:32:54 GMT
  128.  
  129. I want to create a floating palette in MacApp, much like Hypercard's tools
  130. window.  I'd also like it to be resizable and scrollable.  I've created
  131. a palette view in MacApp as a subview of TGridView, but the window that
  132. it's installed in becomes hidden when another window is activated
  133. on top of it.  I want the palette window to always be showing, and I don't
  134. want any sense of it being activated or deactivated.
  135.  
  136. Any suggestions?
  137.  
  138. poon@parc.xerox.com
  139.  
  140.  
  141. +++++++++++++++++++++++++++
  142.  
  143. From: eyes@cs.ubc.ca (Eye Care Centre)
  144. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  145. Date: Thu, 23 Jul 92 03:13:06 GMT
  146.  
  147. In article <poon.711840774@roo> poon@parc.xerox.com (Alex Poon) writes:
  148. >I want to create a floating palette in MacApp, much like Hypercard's tools
  149. >window.  I'd also like it to be resizable and scrollable.  I've created
  150. >a palette view in MacApp as a subview of TGridView, but the window that
  151. >it's installed in becomes hidden when another window is activated
  152. >on top of it.  I want the palette window to always be showing, and I don't
  153. >want any sense of it being activated or deactivated.
  154.  
  155. MacApp 2.0.1 has floating window support provided in a folder containing
  156. experimental enhancements (I forget the exact name of the folder). Just
  157. move the files in this folder to your MacApp libraries sources folder and
  158. examine the included examples to see how to use the new classes.
  159.  
  160. MacApp 3.0 has a built-in TFloatingWindow class. I'm not sure if it supports
  161. resizing, though, not having used it yet.
  162.  
  163. Bill Kiss, Programmer
  164. Dept. of Ophthalmology, UBC
  165.  
  166.  
  167. +++++++++++++++++++++++++++
  168.  
  169. From: mlanett@Apple.COM (Mark Lanett)
  170. Date: 23 Jul 92 04:37:50 GMT
  171. Organization: Apple Computer Inc., Cupertino, CA
  172.  
  173. poon@parc.xerox.com (Alex Poon) writes:
  174.  
  175. >I want to create a floating palette in MacApp, much like Hypercard's tools
  176. >window.  I'd also like it to be resizable and scrollable.  I've created
  177. >a palette view in MacApp as a subview of TGridView, but the window that
  178. >it's installed in becomes hidden when another window is activated
  179. >on top of it.  I want the palette window to always be showing, and I don't
  180. >want any sense of it being activated or deactivated.
  181.  
  182. MacApp 3: trivial. Just create a window and hit the appropriate check boxes
  183. in ViewEdit. These will be: window type (WindoidWDEF), Floats, Doesn't Generate
  184. Actiavtes, Hides on Suspend. Create it like you would any other window and
  185. Ta-da! it'll float around. Like I said, trivial. Oh yes, you have to call
  186. InitUFloatWindow() in main().
  187.  
  188. MacApp 2: harder. 90% of it is done for you, it just that the last 10% is
  189. non-obvious. First off, there was an unsupported floating window package on
  190. ETO (there was a year ago when I used it, I can't get to an ETO now to check)
  191. that you'll need to incorporate. That's the 90% part. You need to specify the
  192. floating window resource template via Rez, not ViewEdit, because ViewEdit can't
  193. put out the refCon for the floating window. I had a Rez template with just
  194. the floater and put all my views in a separate view (created with ViewEdit). 
  195. Creating a window becomes a matter of floater=NewTemplateWindow(...);
  196. DoCreateViews(floater,...);
  197.  
  198. It's easier in 3.0, obviously. Also tabbing and other things are handled much
  199. better. Also there's a snippet doing floaters on the developer CD (also on
  200. ftp, I guess, but it's down right now), which is, alas, for MacApp 3.0b2.
  201. - -- 
  202. /*      Well, you wanted a command line interface, you got one, and now you
  203. can't figure out how to use it without the manual.  What were you expecting?
  204. That's how command line interfaces work. - John Nagle */
  205.  
  206. +++++++++++++++++++++++++++
  207.  
  208. From: mcmath@csb1.nlm.nih.gov (Chuck McMath)
  209. Date: 23 Jul 92 14:19:19 GMT
  210. Organization: MSD
  211.  
  212. In article <poon.711840774@roo>, poon@parc.xerox.com (Alex Poon) wrote:
  213. > I want to create a floating palette in MacApp, much like Hypercard's tools
  214. > window.  I'd also like it to be resizable and scrollable.  I've created
  215. > a palette view in MacApp as a subview of TGridView, but the window that
  216. > it's installed in becomes hidden when another window is activated
  217. > on top of it.  I want the palette window to always be showing, and I don't
  218. > want any sense of it being activated or deactivated.
  219. > Any suggestions?
  220. > poon@parc.xerox.com
  221.  
  222. Well, if you're using MacApp 3.0 you can easily create a floating window
  223. with your stuff in it. There are additions to 2.0 to add floating palette
  224. capabilities.  The additions work; I've used them successfully in a program
  225. I wrote.
  226.  
  227. You need to set up the appropriate flags using ViewEdit (right?) and the
  228. palette window needs to be a TFloatWindow (this is 3.0 I'm describing
  229. here).
  230.  
  231. It's not that difficult.
  232.  
  233. chuck
  234.  
  235. |- chuck mcmath - mcmath@csb1.nlm.nih.gov - MSD, Inc. ------------|
  236. |- National Library of Medicine - National Institutes of Health --|
  237. |- Bethesda, MD 20894 ------------ C++ causes cancer -------------|
  238. |- "Hey batter, hey batter, hey batter, swing" - Anon. -----------|
  239.  
  240. +++++++++++++++++++++++++++
  241.  
  242. From: Kent Sandvik (Hacker) <ksand@apple.com>
  243. Date: Tue, 4 Aug 1992 17:46:25 GMT
  244. Organization: Apple
  245.  
  246. In article <70364@apple.Apple.COM> Mark Lanett, mlanett@Apple.COM writes:
  247. >It's easier in 3.0, obviously. Also tabbing and other things are handled
  248. much
  249. >better. Also there's a snippet doing floaters on the developer CD (also
  250. on
  251. >ftp, I guess, but it's down right now), which is, alas, for MacApp 3.0b2.
  252.  
  253. I'm going to fix this for 3.0.1 this Thursday. Don't worry! The other
  254. sample
  255. concerning behaviors I wrote also has a floating window.
  256.  
  257. Kent Sandvik/DTS
  258.  
  259. ---------------------------
  260.  
  261. From: rdd@cactus.org (Robert Dorsett)
  262. Subject: Access to Map cdev data
  263. Organization: Capital Area Central Texas UNIX Society, Austin, Tx
  264. Date: Mon, 27 Jul 1992 05:34:00 GMT
  265.  
  266. I haven't been able to find a good answer to this in IM: is there a way
  267. to access the lat/long data *and* the relative UTC time as entered in the
  268. Map cdev?  I have a friend who's writing a satellite-tracker; it makes
  269. some sense for him to initialize his information from the map cdev.
  270.  
  271. Please reply via email; I'll summarize.
  272.  
  273.  
  274.  
  275. - ---
  276. Robert Dorsett
  277. rdd@cactus.org
  278. ...cs.utexas.edu!cactus.org!rdd
  279.  
  280. +++++++++++++++++++++++++++
  281.  
  282. From: sdorner@qualcom.qualcomm.com (Steve Dorner)
  283. Organization: Qualcomm, Inc., San Diego, CA
  284. Date: Wed, 5 Aug 1992 15:01:25 GMT
  285.  
  286. You wrote in comp.sys.mac.programmer:
  287. >I haven't been able to find a good answer to this in IM: is there a way
  288. >to access the lat/long data *and* the relative UTC time as entered in the
  289. >Map cdev?  I have a friend who's writing a satellite-tracker; it makes
  290. >some sense for him to initialize his information from the map cdev.
  291. >
  292. >Please reply via email; I'll summarize.
  293.  
  294. I know this is an old article, but I didn't see any summary.  This is
  295. documented in (of all places) the Script Manager chapter of IM-5.  The
  296. routine name is "ReadLocation".
  297.  
  298. You cannot tell if the mac's time is DST or not; the "dlsDelta" flag
  299. mentioned is not implemented by anything; there are not even any units
  300. specified for it.
  301. - -- 
  302. Steve Dorner, Qualcomm, Inc.
  303. Yes, I'm still working on Eudora and it's still free.
  304.  
  305. ---------------------------
  306.  
  307. From: d88-jwa@cyklop.nada.kth.se (Jon W{tte)
  308. Subject: Slaughtering Lambs in the Name of Jim Reekes
  309. Date: 4 Aug 92 13:21:56 GMT
  310. Organization: Royal Institute of Technology, Stockholm, Sweden
  311.  
  312.  
  313. This is the dying sound channel from hell problem.
  314.  
  315. I am playing some sounds, asynchronously, and sometimes
  316. (repeatable but not predictable) the sound channel just
  317. dies and doesn't play anymore. Re-initting the channel
  318. makes sound come back.
  319.  
  320. Any help appreciated, here's the code:
  321. (And you may use it with credits to me in your about box
  322. and a free copy of your app to me :-)
  323.  
  324. //    GameSounds.c
  325.  
  326.  
  327. #include "GameSounds.h"
  328. #include "Fail.h"
  329.  
  330.  
  331. Handle sounds [ NUM_SOUNDS ] ;
  332. Boolean ldRes = 0 ;
  333. SndChannelPtr sndChannel = NULL ;
  334.  
  335.  
  336. void
  337. LoadSounds ( void )
  338. {
  339.     int i ;
  340.  
  341.     if ( sndChannel ) {
  342.  
  343.         return ;
  344.     }
  345.     if ( ! ldRes ) {
  346.  
  347.         for ( i = 0 ; i < NUM_SOUNDS ; i ++ ) {
  348.  
  349.             sounds [ i ] = GetResource ( 'snd ' , i + 128 ) ;
  350.             if ( ! sounds [ i ] ) {
  351.  
  352.                 Fail ( -192 ) ;
  353.             }
  354.             {
  355.                 short * s = ( short * ) * sounds [ i ] ;
  356.  
  357.                 if ( ( s [ 0 ] != 1 ) || ( s [ 1 ] != 1 ) ) {
  358.  
  359.                     Fail ( -50 ) ;
  360.                 }
  361.             }
  362.             DetachResource ( sounds [ i ] ) ;
  363.             MoveHHi ( sounds [ i ] ) ;
  364.             HLock ( sounds [ i ] ) ;
  365.         }
  366.         ldRes = 1 ;
  367.     }
  368.  
  369.     sndChannel = NULL ;
  370.     i = SndNewChannel ( & sndChannel , sampledSynth , initMono + initNoInterp , NULL ) ;
  371.     if ( i ) {
  372.  
  373.         Fail ( i ) ;
  374.     }
  375. }
  376.  
  377.  
  378. void
  379. GameSound ( short ix )
  380. {
  381.     SndCommand cmd ;
  382.  
  383.     if ( ! sndChannel ) {
  384.  
  385.         LoadSounds ( ) ;
  386.     }
  387.     cmd . cmd = flushCmd ;
  388.     cmd . param1 = 0 ;
  389.     cmd . param2 = 0 ;
  390. //    SndDoImmediate ( sndChannel , & cmd ) ;
  391.     cmd . cmd = quietCmd ;
  392.     cmd . param1 = 0 ;
  393.     cmd . param2 = 0 ;
  394.     SndDoImmediate ( sndChannel , & cmd ) ;
  395.     cmd . cmd = bufferCmd ;
  396.     cmd . param1 = 0 ;
  397.     cmd . param2 = ( long ) ( ( char * ) * sounds [ ix ] ) + 20 ;
  398.     SndDoCommand ( sndChannel , & cmd , TRUE ) ;
  399.     cmd . cmd = quietCmd ;
  400.     cmd . param1 = 0 ;
  401.     cmd . param2 = 0 ;
  402. //    SndDoCommand ( sndChannel , & cmd , TRUE ) ;
  403. }
  404.  
  405.  
  406. void
  407. DoneSounds ( void )
  408. {
  409.     SndCommand cmd ;
  410.  
  411.     if ( ! sndChannel ) {
  412.  
  413.         return ;
  414.     }
  415.     cmd . cmd = flushCmd ;
  416.     cmd . param1 = 0 ;
  417.     cmd . param2 = 0 ;
  418.     SndDoImmediate ( sndChannel , & cmd ) ;
  419.     cmd . cmd = quietCmd ;
  420.     cmd . param1 = 0 ;
  421.     cmd . param2 = 0 ;
  422.     SndDoImmediate ( sndChannel , & cmd ) ;
  423.     SndDisposeChannel ( sndChannel , TRUE ) ;
  424.     sndChannel = NULL ;
  425. }
  426.  
  427.  
  428. void
  429. ReInitSounds ( void )
  430. {
  431.     SndCommand cmd ;
  432.  
  433.     if ( ! sndChannel ) {
  434.  
  435.         LoadSounds ( ) ;
  436.     }
  437.     cmd . cmd = flushCmd ;
  438.     cmd . param1 = 0 ;
  439.     cmd . param2 = 0 ;
  440.     SndDoImmediate ( sndChannel , & cmd ) ;
  441.     cmd . cmd = quietCmd ;
  442.     cmd . param1 = 0 ;
  443.     cmd . param2 = 0 ;
  444.     SndDoImmediate ( sndChannel , & cmd ) ;
  445.     cmd . cmd = reInitCmd ;
  446.     cmd . param1 = 0 ;
  447.     cmd . param2 = initMono + initNoInterp ;
  448.     SndDoImmediate ( sndChannel , & cmd ) ;
  449. }
  450. - -- 
  451.       Jon W{tte, Svartmangatan 18, S-111 29 Stockholm, Sweden
  452.                   h+@nada.kth.se    +46-10-141652
  453.  
  454.     My landlord have forbidden my cat to run around on the roof.
  455.  
  456. +++++++++++++++++++++++++++
  457.  
  458. From: rbarris@orion.oac.uci.edu (Robert C. Barris)
  459. Organization: University of California, Irvine
  460. Date: 6 Aug 92 05:47:42 GMT
  461.  
  462. In article <D88-JWA.92Aug4142157@cyklop.nada.kth.se> d88-jwa@cyklop.nada.kth.se (Jon W{tte) writes:
  463. >
  464. >This is the dying sound channel from hell problem.
  465. >
  466. >I am playing some sounds, asynchronously, and sometimes
  467. >(repeatable but not predictable) the sound channel just
  468. >dies and doesn't play anymore. Re-initting the channel
  469. >makes sound come back.
  470.  
  471. I have seen this and had to deal with it.
  472.  
  473. In a nutshell, the Sound Manager is not perfect. If it misses an interrupt
  474. from the ASC for any reason (LocalTalk is popular cause) then it just forgets
  475. about that output channel (and it never gets fed again).
  476.  
  477. I encountered this problem when using SndPlayDoubleBuffer, and ultimately
  478. implemented a watchdog routine which kept track of the number of ticks
  479. elapsed since the last block of data transferred to the sound chip. If that
  480. number ever went above a certain threshold, it figured 'oops, the channel
  481. stalled' and re-initted it as you mentioned.
  482.  
  483. Obviously it would be nice if the SndMgr did this for us.
  484.  
  485. Rob Barris
  486. Quicksilver Software Inc.
  487. rbarris@orion.oac.uci.edu
  488.  
  489. ---------------------------
  490.  
  491. From: essam@gagme.chi.il.us (Essam Khairullah)
  492. Subject: Setting the volume
  493. Organization: Gagme Public Access UNIX, Chicago, Illinois.
  494. Date: Mon, 3 Aug 1992 20:08:50 GMT
  495.  
  496. I've been trying to write an XCMD to set the speaker volume (in THINK C 5.0) and
  497. I have this weird problem....
  498.  
  499. Basically I originally tried reading the parameter RAM, changing the appropriate
  500. bits for the sound volume, and then writing it back.  I then discovered the low
  501. memory global SdVolume.  Both methods seemed to work, except for the following
  502. problem:
  503.  
  504. Basically the sound volume would not be effected until I activate AfterDark (by
  505. moving the mouse into the appropriate corner) or I open the Sound control panel
  506. and play a sound.  If I just SysBeep without doing one of the above things firstthe old volume would be used.  But if I do one of the above, the sound volume
  507. that I was trying to set would be used.
  508.  
  509. My XCMD is actually an XFCN which also returns the current sound volume.  If I
  510. call it again after setting the volume, the volume it returns is also the right
  511. volume.
  512.  
  513. What am I doing wrong?  Do I need to do something like InitSoundManager (which
  514. as far as IM 1-6 are concerned, doesn't exist).  Do I have to open a new sound
  515. channel or something?  Please let me know if you have any advice!
  516.  
  517. Thanks in advance...
  518.  
  519.  
  520. - -- 
  521.                     Essam Badi' Abu Khalil Khairullah
  522.               essam@gagme.chi.il.us
  523.                  I don't got no fancy signature!
  524. I'm a .signature virus. You can't resist copying me into your .signature!
  525.  
  526. +++++++++++++++++++++++++++
  527.  
  528. From: jeremyr@dcs.qmw.ac.uk (Jeremy Roussak)
  529. Date: 6 Aug 92 18:23:13 GMT
  530. Organization: Computer Science Dept, QMW, University of London
  531.  
  532. In <1992Aug3.200850.14026@gagme.chi.il.us> essam@gagme.chi.il.us (Essam Khairullah) writes:
  533.  
  534. >I've been trying to write an XCMD to set the speaker volume...
  535.  
  536. >Basically I originally tried reading the parameter RAM, changing the appropriate
  537. >bits for the sound volume, and then writing it back.  I then discovered the low
  538. >memory global SdVolume.  Both methods seemed to work, except for the following
  539. >problem:
  540.  
  541. [changes not activated until After Dark run]
  542.  
  543. >What am I doing wrong?
  544.  
  545. There are two relevant low-memory globals. SpVolCtl is a byte
  546. which reflects the parameter RAM volume setting in its low 3
  547. bits. SdVolume is a byte which contains the current speaker
  548. volume.
  549.  
  550. GetSoundVolume() returns the current value of SdVolume.
  551. SetSoundVolume(short) sets SdVolume to the specified value,
  552. with immediate effect, but the change will not persist after
  553. restart.
  554. Changing the low 3 bits of SpVolCtl and then calling WriteParam
  555. makes a change which will come into effect after restart, or
  556. perhaps after running the Sound CP.
  557.  
  558. So,
  559. to change the volume, call GetSoundVolume and SetSoundVolume:
  560. don't forget to be responsible and call SetSoundVolume again to
  561. restore the level
  562.  
  563. to make a permanent change, do the above and also set SpVolCtl
  564. and call WriteParam.
  565.  
  566. I think the above is correct :-)
  567.  
  568. Jeremy
  569.  
  570. ---------------------------
  571.  
  572. From: psc9q@holmes.acc.Virginia.EDU (The Beloved)
  573. Subject: I need a *fast* rand () procedure
  574. Organization: University of Virginia
  575. Date: Wed, 5 Aug 1992 06:25:00 GMT
  576.  
  577. Hello,
  578.  
  579. I'm creating bitmaps filled with a certain percentage of dots. Basically, I
  580. just test to see if "rand () % 100" is less than say, 25%, and draw a point.
  581. Does anyone know of a faster way to do this? I've rewritten rand.c in assembly
  582. but only received a 50% speed improvement. I need something drastically
  583. faster. Below is my assembly code. Could I optimize this somehow?
  584.  
  585. unsigned long   newRand = 1;
  586.  
  587. int   fastrand ()
  588. {
  589.    unsigned int   tempRand;
  590.    
  591.    asm
  592.    {
  593.       move.l   newRand, d0
  594.       mulu.l   #1103515245, d0
  595.       add.w    #12345, d0
  596.       move.l   d0, newRand
  597.       lsr.l    #8, d0
  598.       lsr.l    #8, d0
  599.       and.w    #32767, d0
  600.       move.w   d0, tempRand
  601.    }
  602.    
  603.    return (tempRand);
  604. }
  605.  
  606. Thanks,
  607.  
  608. Paul
  609. - -- 
  610. beloved@virginia.edu                        "Top one, nice one, get sorted."
  611. psc9q@holmes.acc.virginia.edu                         -- Altern8
  612.  
  613. +++++++++++++++++++++++++++
  614.  
  615. From: buckeye@spf.trw.com (John Wallace)
  616. Organization: TRW Data Systems Center, Redondo Beach, CA
  617. Date: Wed, 5 Aug 92 20:42:59 GMT
  618.  
  619. In article <1992Aug5.062500.17133@murdoch.acc.Virginia.EDU> psc9q@holmes.acc.Virginia.EDU (The Beloved) writes:
  620. >Hello,
  621. >
  622. >I'm creating bitmaps filled with a certain percentage of dots. Basically, I
  623. >just test to see if "rand () % 100" is less than say, 25%, and draw a point.
  624. >Does anyone know of a faster way to do this? I've rewritten rand.c in assembly
  625. >but only received a 50% speed improvement. I need something drastically
  626. >faster. Below is my assembly code. Could I optimize this somehow?
  627. >
  628. >unsigned long   newRand = 1;
  629. >
  630. >int   fastrand ()
  631. >{
  632. >   unsigned int   tempRand;
  633. >   
  634. >   asm
  635. >   {
  636. >      move.l   newRand, d0
  637. >      mulu.l   #1103515245, d0
  638. >      add.w    #12345, d0
  639. >      move.l   d0, newRand
  640. >      lsr.l    #8, d0
  641. >      lsr.l    #8, d0
  642. >      and.w    #32767, d0
  643. >      move.w   d0, tempRand
  644. >   }
  645. >   
  646. >   return (tempRand);
  647. >}
  648. >
  649. >Thanks,
  650. >
  651. >Paul
  652. >-- 
  653. >beloved@virginia.edu                        "Top one, nice one, get sorted."
  654. >psc9q@holmes.acc.virginia.edu                         -- Altern8
  655.  
  656. There are a couple of things you may want to do to speed things up.
  657. Rather than shifting by 16, just call the 'swap' command to move the
  658. high word into the low word.  Also, why do you add 32767?  This will
  659. just convert all of your positives into negatives and your negatives
  660. into positives, so it seems to be of no possible value.
  661.  
  662. Also rather than doing it rand()%100, you may want to do it
  663. rand()%128, which you would implement as rand()&127, since the %
  664. operation is quite slow.  Then rather than comparing it to 25, you can
  665. compare it to 25*(128/100), where you compute that value only once outside of
  666. your pixel plotting code.
  667.  
  668. You may also want to the the %128 operation in the code itself, and
  669. since C returns values in d0 (I think; I do most of my high level
  670. coding in Pascal), you could recode the entire thing as:
  671.  
  672.  
  673. unsigned long   newRand = 1;
  674.  
  675. int   RandMod128 ()
  676. {
  677.    asm
  678.    {
  679.       move.l   newRand, d0
  680.       mulu.l   #1103515245, d0
  681.       add.w    #12345, d0
  682.       move.l   d0, newRand
  683.       swap     d0         ; move high word of random value into low word
  684.       and.w    #127,d0             ; get value in range from 0..127
  685.       unlink   a6         ; undo the C routine's link a6
  686.       rts             ; return to caller
  687.    }
  688. }
  689.  
  690.  
  691. Cheers!
  692. John
  693. - -------------
  694. John Wallace        buckeye@spf.trw.com
  695.  
  696. +++++++++++++++++++++++++++
  697.  
  698. From: k044477@hobbes.kzoo.edu (Jamie R. McCarthy)
  699. Organization: Kalamazoo College
  700. Date: Wed, 5 Aug 1992 21:43:15 GMT
  701.  
  702. I don't want to pick on you, John, but I just have to say this...  :-)
  703.  
  704. buckeye@spf.trw.com (John Wallace) writes:
  705. >psc9q@holmes.acc.Virginia.EDU (The Beloved) writes:
  706. >>
  707. >>I'm creating bitmaps filled with a certain percentage of dots. Basically, I
  708. >>just test to see if "rand () % 100" is less than say, 25%, and draw a point.
  709. >
  710. >There are a couple of things you may want to do to speed things up.
  711. >Rather than shifting by 16, just call the 'swap' command to move the
  712. >high word into the low word.
  713.  
  714. True--twice as fast...
  715.  
  716. >Also, why do you add 32767?
  717.  
  718. He 'and'ed, which masks off the lower 16 bits (which doesn't affect the
  719. result, in this case...)
  720.  
  721. >Also rather than doing it rand()%100, you may want to do it
  722. >rand()%128, which you would implement as rand()&127, since the %
  723. >operation is quite slow.  Then rather than comparing it to 25, you can
  724. >compare it to 25*(128/100)
  725.  
  726. In C, 25*(128/100) equals 25.  I suspect you want (25*128)/100.
  727.  
  728. >...since C returns values in d0 (I think; I do most of my high level
  729. >coding in Pascal), you could recode...:
  730. >
  731. >int   RandMod128 ()
  732. >{
  733. >   asm
  734. >   {
  735. >      move.l   newRand, d0
  736. >      mulu.l   #1103515245, d0
  737. >      add.w    #12345, d0
  738. >      move.l   d0, newRand
  739. >      swap     d0         ; move high word of random value into low word
  740. >      and.w    #127,d0             ; get value in range from 0..127
  741. >      unlink   a6         ; undo the C routine's link a6
  742. >      rts             ; return to caller
  743. >   }
  744. >}
  745.  
  746. This will work (except that "unlink" is spelled "unlk"), but, as the
  747. manual says, "Do not use the RTS instruction unless you're absolutely
  748. sure you know what you're doing.  If you want to return a value, always
  749. use a return statement."
  750.  
  751. In this case, I believe the compiler won't be smart enough to realize
  752. you're returning inside the asm block, and will put its own unlk and rts
  753. right after yours.  More important (to me) is the unlk that matches up
  754. with the hidden one at the top of the function.  If you rewrite
  755. RandMod128 to use a local variable, you'd better be alert enough to
  756. catch this.  This kind of coding makes me nervous.
  757.  
  758. If speed is so important that you can't take the time to push and pop
  759. the return value, you should be inlining this function anyway, and
  760. putting both newRand and the constant #12345 into registers if at all
  761. possible.
  762.  
  763. Finally, I hope this code won't be run on a 68000;  it doesn't have a
  764. longword multiply instruction...
  765. - -- 
  766.  Jamie McCarthy      Internet: k044477@kzoo.edu      AppleLink: j.mccarthy
  767.  "When the Constitution was adopted...no human wisdom could foretell the
  768.  sweeping changes...which were to take place.... The conditions are now wholly
  769.  different, and wholly different action is called for."  - T. Roosevelt, 1901
  770.  
  771. +++++++++++++++++++++++++++
  772.  
  773. From: kaufman@Xenon.Stanford.EDU (Marc T. Kaufman)
  774. Organization: CS Department, Stanford University, California, USA
  775. Date:  6 Aug 92 00:51:09 GMT
  776.  
  777. psc9q@holmes.acc.Virginia.EDU (The Beloved) writes:
  778.  
  779. >I'm creating bitmaps filled with a certain percentage of dots. Basically, I
  780. >just test to see if "rand () % 100" is less than say, 25%, and draw a point.
  781.  
  782. For the random number generator, if you have a 69020 try this:
  783.  
  784.         move.l    RandomSeed,D1
  785.         mulu.l    #16807,D0:D1        ; long multiply
  786.         divu.l    #$7fffffff,D0:D1    ; modulo 2^31 -1
  787.         move.l    D0,RandomSeed
  788.  
  789. - -- 
  790. Marc Kaufman (kaufman@CS.Stanford.EDU)
  791.  
  792.  
  793. +++++++++++++++++++++++++++
  794.  
  795. From: creiman@Apple.COM (Charlie Reiman)
  796. Date: 5 Aug 92 23:54:00 GMT
  797. Organization: Apple Computer Inc., Cupertino, CA
  798.  
  799. psc9q@holmes.acc.Virginia.EDU (The Beloved) writes:
  800.  
  801. >Hello,
  802.  
  803. >I'm creating bitmaps filled with a certain percentage of dots. Basically, I
  804. >just test to see if "rand () % 100" is less than say, 25%, and draw a point.
  805. >Does anyone know of a faster way to do this? I've rewritten rand.c in assembly
  806. >but only received a 50% speed improvement. I need something drastically
  807. >faster. Below is my assembly code. Could I optimize this somehow?
  808.  
  809.  < Code deleted >
  810.  
  811. Is it just me, or does every UseNet programming group seem to deal with
  812. this issue at least once a year?
  813.  
  814. Now that my obligitory nit-picking is done, let's get down to business.
  815.  
  816. First off: using n%100 is bad. It involves taking an integer division, which
  817. is unnecessary. Use (n & 0xff) < 0x40 or some such. Remember: Logical AND is
  818. the same as integer modulus. Also, don't assume the compiler is smart enough
  819. to translate ( N % 256 ) => ( N & 255 ). Last time I checked, MPW C wasn't
  820. managing the simlar translation for division so I wouldn't count on
  821. it working for modulus.
  822.  
  823. If you are looking for speed, there is one easy way to get what you
  824. need.  In your case there happens to be a second, sneaky way that I'll
  825. also mention last.
  826.  
  827. 1) Buffers. Create a small buffer of, oh, say 16 words. Fill 'em with 
  828.    random numbers. Then create a counter, and init it to zero and
  829.    an index into the table, also inited to zero. When you need a random
  830.    number, call a routine that works like this:
  831.  
  832.    returnValue = table[index]
  833.    index = (index + 1) mod 16        # yes, you should use & 0xf, but this is
  834.    counter += 1                # pseudo-code.
  835.    if ( counter == 7 )
  836.        table[index]=Random()
  837.        counter = 0
  838.    return returnValue
  839.  
  840.    This is cheap and easy. It will also reduce the randomness of your
  841.    numbers quite a bit. Just be sure you don't fall into mindless loops
  842.    (ie. change the counter ceiling to 8. Only two values in the buffer
  843.    will change in this case) Needless to say, you shouldn't use this
  844.    algorithim for any scientific computations.
  845.  
  846.    In case you haven't noticed, I didn't test this code before posting 
  847.    it. Caveat Emptor.
  848.  
  849. 2) Tiling. Create a small tile of the appropriate darkness, then tile it
  850.    over the entire bitmap using copybits.
  851.  
  852. Good luck.
  853. - -- 
  854. Charlie Reiman - Speaking as an individual, not for Apple Computer.
  855. creiman@apple.com
  856.         "NEW! Posting Lite! 98% fact free!"
  857.  
  858. +++++++++++++++++++++++++++
  859.  
  860. From: bruner@sp15.csrd.uiuc.edu (John Bruner)
  861. Organization: CSRD, University of Illinois
  862. Date: 6 Aug 92 09:03:31
  863.  
  864. Using a pseudo-random number generator to create a large bitmap is,
  865. by nature, going to be slow.  If the intent of the code is to do some
  866. sort of image dithering, I suggest you consult the recent issue of
  867. *develop* (the "Winter 1992" issue, I believe), where the topic was
  868. discussed.
  869.  
  870. If you really do need to generate pseudo-random numbers and test them
  871. against a threshold, I suggest that you treat the values as 32-bit
  872. unsigned fixed point numbers and do the threshold with a comparison
  873. rather than shifting and masking.  You could use the fixed point
  874. routines the the Toolbox provides, but they use a different
  875. representation, so you'd have to account for that.  Alternately, you
  876. can do something like the following:
  877.  
  878. 1) Generate a 32-bit fraction representing the desired percentage.
  879. This requires a divide (which makes it expensive), but presumably you
  880. will only do this once, whereas you will generate many pseudo-random
  881. numbers.  You produce the fraction by dividing 100 into a 64-bit
  882. number whose binary point is located right in the middle, i.e., you
  883. want to divide (percentage<<32) by 100.  Assuming "percentage" is less
  884. than 100 this will produce a 32-bit quotient with the binary point to
  885. the left of all 32 bits, a fraction in the range 0..(1 - 2**(-32)).
  886. Treat 100 as a special case and set the fraction to the maximum
  887. possible value.  I don't have my 68030 manual handy, but I believe it
  888. is something like this:
  889.  
  890.     unsigned long percentage, threshold;
  891.     
  892.     asm {
  893.         moveq    percentage, d0
  894.         cmp.l    #100, d0
  895.         bcc    @1
  896.     
  897.         /* percentage is < 100 */
  898.         moveq    #0, d1
  899.         divu.l    #100, d0:d1
  900.         move.l    d1, threshold        /* quotient is fraction */
  901.         bra    @2
  902.     
  903.         /* percentage is >= 100: use maximum fraction */
  904.     @1:    move.l    #0xffffffff, threshold
  905.     @2:
  906.     }
  907.     
  908.  
  909. 2) Generate the random number in the conventional fashion, e.g.:
  910.  
  911.     extern unsigned long rand();
  912.     
  913.     asm {
  914.     rand:    move.l    newRand, d0
  915.         mulu.l    #1103515245, d0
  916.         add.l    #12345, d0    /* note: ADD.L rather than ADD.W */
  917.         move.l    d0, newRand
  918.         rts
  919.     }
  920.  
  921.     
  922. 3) Perform the threshold operation with an unsigned comparison:
  923.  
  924.     if (rand() <= threshold) {
  925.         /* set the pixel */
  926.     }
  927.  
  928. If this still isn't fast enough, and you are willing to sacrifice
  929. randomness, you might consider using 16-bit arithmetic.  The choice of
  930. the multiplier and addend are important, so if you go this route
  931. you'll need to do some further research (Knuth is a good place to
  932. start).
  933. - --
  934. (Dr.) John Bruner, Deputy Director            bruner@csrd.uiuc.edu
  935. Center for Supercomputing Research & Development    (217) 244-4476 (voice)
  936. University of Illinois at Urbana-Champaign        (217) 244-1351 (FAX)
  937. 465 CSRL, MC-255; 1308 West Main St.; Urbana, IL  61801-2307
  938.  
  939. +++++++++++++++++++++++++++
  940.  
  941. From: lipa@camis.Stanford.EDU (Bill Lipa)
  942. Date: 6 Aug 92 16:00:59 GMT
  943. Organization: Stanford School of Medicine
  944.  
  945.  
  946. Try the algorithm for equation 7 described in section 3.2.2 of Knuth. It
  947. doesn't require any multiplication, division, or shifts, so it is probably
  948. faster than the other methods that have been discussed. It uses a table of
  949. 55 random numbers that can be generated slowly (or even precomputed) to
  950. make a sequence of 2^55 - 1 new pseudo-random numbers.
  951.  
  952. Knuth chapter 3 is really the place to go for random number techniques.
  953.  
  954. Bill Lipa
  955. lipa@camis.stanford.edu
  956.  
  957. +++++++++++++++++++++++++++
  958.  
  959. From: pgj@Apple.COM (Paul Jensen)
  960. Date: 6 Aug 92 21:51:30 GMT
  961. Organization: A/UX Engineering, Apple Computer Inc.
  962.  
  963.  
  964. All the comments in the previous replies are on target: "%" is slow,
  965. mod-power-of-two is fast, you're better off using a dithering algorithm
  966. to accomplish what you want.
  967.  
  968. However... if you *really* need a fast random numnber generator, there are
  969. algorithms better than the ones presented here, most of which are variations
  970. on the Linear (Lehmer) Congruential method.  In a previous incarnation
  971. writing Monte-Carlo simulators, I was fond of the Feedback Shift Register
  972. algorithm which is not only has better statistical properties, but is
  973. fast: 2 adds, 2 compares, and one XOR (i.e. *no* multiply).  See 
  974. JACM Vol. 20, #3, July '73, pp 456-68 for details (as well as some of 
  975. the ugliest FORTRAN you will ever lay eyes on).
  976.  
  977. The 2nd edition of Knuth Vol 2 is probably the last word on this subject:
  978. 170+ pages of mind-numbing detail.  Knuth favors a different algorithm, but
  979. he is less concerned with speed.
  980.  
  981.  
  982.                     /PGJ
  983.  
  984. ---------------------------
  985.  
  986. From: gurgle@netcom.com (Pete Gontier)
  987. Subject: MacTCP: can't send very many single bytes in a row
  988. Date: 30 Jul 92 02:34:55 GMT
  989. Organization: cellular
  990.  
  991. Last night I tried to do an intuitive thing: base a function called
  992. tcp_puts on a function called tcp_putchar. tcp_puts was, of course,
  993. calling tcp_putchar for each character in the string, and tcp_putchar
  994. was sending each character to a (Mac)TCP connection. I knew this was
  995. inefficient, but I wanted to see just *how* inefficient it was. Turns
  996. out it was more than inefficient; after a few characters, it *hung*.
  997. So now I don't have a tcp_putchar; I just blast the entire string
  998. every time with tcp_puts and if I need to output a single char, I fake
  999. a string and send it to tcp_puts. I don't send a single character any
  1000. too often, so that is not a problem.
  1001.  
  1002. So the question is --- is this hanging behavior a widely experienced
  1003. thing? An acknowledged bug, perhaps?
  1004.  
  1005. FYI, I'm using MacTCP 1.1.
  1006. - -- 
  1007.  Pete Gontier // EC Technology // gurgle@netcom.com
  1008.  
  1009. +++++++++++++++++++++++++++
  1010.  
  1011. From: peter@cujo.curtin.edu.au (Peter N Lewis)
  1012. Organization: NCRPDA, Curtin University
  1013. Date: Mon, 3 Aug 1992 00:58:08 GMT
  1014.  
  1015. In article <p-pmarm.gurgle@netcom.com>, gurgle@netcom.com (Pete Gontier)
  1016. wrote:
  1017.  
  1018. > So the question is --- is this hanging behavior a widely experienced
  1019. > thing? An acknowledged bug, perhaps?
  1020. > FYI, I'm using MacTCP 1.1.
  1021.  
  1022. MacTCP is an acknowledged bug :-)
  1023.  
  1024. Were you using asyncronous sends?  That would definitely cause a problem
  1025. since there is invariably a limit to the number of async control calls you
  1026. can have at any time (this bit me baddly in the .XPP driver where it
  1027. happily said 'yeah, sure I can do that asyncronously' and threw it away)-:
  1028.  
  1029. As a side note, it is generally better to write a routine for puts instead
  1030. of putchar and have putchar call puts instead - if you are writing a string
  1031. this will be much more efficient, and if you are writing a char it will
  1032. only be mildly less efficent, and as a general rule, you write more strings
  1033. than chars.  This would apply to any kind of writes, TCP, ADSP, File
  1034. System, serial lines whatever.
  1035.  
  1036. Have fun,
  1037.    Peter.
  1038.  
  1039. _______________________________________________________________________
  1040. Peter N Lewis, NCRPDA, Curtin University       peter@cujo.curtin.edu.au
  1041. GPO Box U1987, Perth WA 6001, AUSTRALIA             FAX: +61 9 367 8141
  1042.  
  1043. +++++++++++++++++++++++++++
  1044.  
  1045. From: gurgle@netcom.com (Pete Gontier)
  1046. Date: Mon, 03 Aug 92 04:44:48 GMT
  1047. Organization: cellular
  1048.  
  1049. peter@cujo.curtin.edu.au (Peter N Lewis) writes:
  1050.  
  1051. >Were you using asyncronous sends?  That would definitely cause a problem
  1052. >since there is invariably a limit to the number of async control calls you
  1053. >can have at any time (this bit me baddly in the .XPP driver where it
  1054. >happily said 'yeah, sure I can do that asyncronously' and threw it away)-:
  1055.  
  1056. Unfortunately, they were synchronous sends. About 20 1-byte synchronous
  1057. sends.
  1058.  
  1059. >As a side note, it is generally better to write a routine for puts instead
  1060. >of putchar and have putchar call puts...
  1061.  
  1062. After a while, I decided that was the case. But it's still more intuitive
  1063. to do it the other way around, and I had to be forced into doing it this
  1064. way before I realized it was better.
  1065. - -- 
  1066.  Pete Gontier // EC Technology // gurgle@netcom.com
  1067.  
  1068. +++++++++++++++++++++++++++
  1069.  
  1070. From: ejohnson@void.ncsa.uiuc.edu (Eric E. Johnson)
  1071. Organization: University of Illinois at Urbana
  1072. Date: Wed, 5 Aug 1992 20:30:45 GMT
  1073.  
  1074. peter@cujo.curtin.edu.au (Peter N Lewis) writes:
  1075.  
  1076. >Were you using asyncronous sends?  That would definitely cause a problem
  1077. >since there is invariably a limit to the number of async control calls you
  1078. >can have at any time (this bit me baddly in the .XPP driver where it
  1079. >happily said 'yeah, sure I can do that asyncronously' and threw it away)-:
  1080.  
  1081. Does anyone know what that limit is?  Is the limit related to how many
  1082. async calls are placed, or is it the number of async calls that have
  1083. yet to complete?
  1084.  
  1085. Eric
  1086.  
  1087. +++++++++++++++++++++++++++
  1088.  
  1089. From: peter@cujo.curtin.edu.au (Peter N Lewis)
  1090. Organization: NCRPDA, Curtin University
  1091. Date: Sun, 9 Aug 1992 05:34:39 GMT
  1092.  
  1093. In article <ejohnson.713046645@void>, ejohnson@void.ncsa.uiuc.edu (Eric E.
  1094. Johnson) wrote:
  1095. > peter@cujo.curtin.edu.au (Peter N Lewis) writes:
  1096. > >Were you using asyncronous sends?  That would definitely cause a problem
  1097. > >since there is invariably a limit to the number of async control calls you
  1098. > >can have at any time (this bit me baddly in the .XPP driver where it
  1099. > >happily said 'yeah, sure I can do that asyncronously' and threw it away)-:
  1100. > Does anyone know what that limit is?  Is the limit related to how many
  1101. > async calls are placed, or is it the number of async calls that have
  1102. > yet to complete?
  1103.  
  1104. There is a table of machine dependent limits in IM V-519, including the
  1105. number of concurrent ATP SendRequests (6-12), concurrent ATP Responses
  1106. (8-32), Concurrent NBP Requests (1-10).  I'm not sure about the limit of
  1107. XPP async calls, its probabbly directly related to the limit of ASP calls.
  1108.  
  1109. HTH,
  1110.    Peter.
  1111.  
  1112. _______________________________________________________________________
  1113. Peter N Lewis, NCRPDA, Curtin University       peter@cujo.curtin.edu.au
  1114. GPO Box U1987, Perth WA 6001, AUSTRALIA             FAX: +61 9 367 8141
  1115.  
  1116. ---------------------------
  1117.  
  1118. From: gb2a+@andrew.cmu.edu (George J. Baxter)
  1119. Subject: AppleEvent passing address
  1120. Date: 4 Aug 92 11:20:13 GMT
  1121. Organization: Science & Technology Center, Carnegie Mellon, Pittsburgh, PA
  1122.  
  1123. Dear World:
  1124.     I'm trying to pass a pointer to a string through an appleEvent to
  1125. another program.  A tiny little problem occurs when I try to use this
  1126. address, however, and that is that I get a nice bus error.  So pleasing
  1127. to the eye to see that MacsBug screen pop up.  Anyway, why is this
  1128. occurring, and how do I go about doing this correctly?
  1129.     Much Grace,
  1130.         -George Baxter
  1131. - -----------------------
  1132. gb2a@andrew.cmu.edu            baxter@a.cfr.cmu.edu
  1133.  
  1134. "Only a Hawaiian can say Humuhumunukunukuapuaa five times fast, correctly."
  1135.  
  1136. "I think we're in for a bad spell of wether."
  1137.  
  1138. +++++++++++++++++++++++++++
  1139.  
  1140. From: jpugh@apple.com (Jon Pugh)
  1141. Date: 8 Aug 92 03:46:03 GMT
  1142. Organization: Apple Computer, Inc.
  1143.  
  1144. In article <keThVha00UzxE3g1ht@andrew.cmu.edu>, gb2a+@andrew.cmu.edu
  1145. (George J. Baxter) wrote:
  1146. > Dear World:
  1147. >     I'm trying to pass a pointer to a string through an appleEvent to
  1148. > another program.  A tiny little problem occurs when I try to use this
  1149. > address, however, and that is that I get a nice bus error.  So pleasing
  1150. > to the eye to see that MacsBug screen pop up.  Anyway, why is this
  1151. > occurring, and how do I go about doing this correctly?
  1152.  
  1153. Rule #1
  1154.  
  1155. DON'T DON'T DON'T DON'T DON'T DON'T DON'T DON'T DON'T DON'T DON'T DON'T
  1156. DON'T 
  1157.  
  1158. Rule #2
  1159.  
  1160. Pretend like there is memory protection and every application has it's own
  1161. inalienable partition.
  1162.  
  1163. Rule #3
  1164.  
  1165. Don't even THINK about passing pointers around in AppleEvents.
  1166.  
  1167. Rule #4
  1168.  
  1169. Pass the data, not the reference.
  1170.  
  1171. Rule #5
  1172.  
  1173. There is NO rule 5.
  1174.  
  1175. Rule #6
  1176.  
  1177. No poofters.
  1178.  
  1179.  
  1180. Jon
  1181.  
  1182. Disclaimer:
  1183.   We're very flexible on the no poofters rule.  Rule #5 is absolute though.
  1184.  
  1185. +++++++++++++++++++++++++++
  1186.  
  1187. From: daven@notable.com (Dave Newman)
  1188. Date: Sat, 8 Aug 92 18:11:54 PST
  1189. Organization: Notable Technologies, Inc.
  1190.  
  1191.  
  1192. In article <jpugh-070892204135@90.20.3.205> (comp.sys.mac.programmer), jpugh@apple.com (Jon Pugh) writes:
  1193. | In article <keThVha00UzxE3g1ht@andrew.cmu.edu>, gb2a+@andrew.cmu.edu
  1194. | (George J. Baxter) wrote:
  1195. | > 
  1196. | > Dear World:
  1197. | >     I'm trying to pass a pointer to a string through an appleEvent to
  1198. | > another program.  A tiny little problem occurs when I try to use this
  1199. | > address, however, and that is that I get a nice bus error.  So pleasing
  1200. | > to the eye to see that MacsBug screen pop up.  Anyway, why is this
  1201. | > occurring, and how do I go about doing this correctly?
  1202. | Rule #1
  1203. | DON'T DON'T DON'T DON'T DON'T DON'T DON'T DON'T DON'T DON'T DON'T DON'T
  1204. | DON'T 
  1205.  
  1206. << remaining rules deleted for brevity >>
  1207.  
  1208. There's a corollary worth noting.
  1209.  
  1210. Corollary #1
  1211.  
  1212. Passing another application a pointer into your heap, whether it be AppleEvents,
  1213. PPC, or your own private IAC hack, is just asking for that application to screw
  1214. with your data, corrupt your heap, and generally wreak havoc.
  1215.  
  1216. In short, pointer out, garbage in.
  1217.  
  1218. - --Dave
  1219.  
  1220. - -----------------------------------------------------------
  1221. Dave Newman                 |  AOL:      AFC Tinman
  1222. Artillery Spotter           |  ALink:    TINMAN
  1223. Notable Technologies, Inc.  |  CIS:      70743,3323
  1224. Voice:    510.208.4449      |  internet: daven@notable.com
  1225. FAX:      510.444.4493      |  
  1226. - -----------------------------------------------------------
  1227.  
  1228. ---------------------------
  1229.  
  1230. From: mgraf@sydvm1.VNET.IBM.COM (Michael Graf)
  1231. Date: Mon, 10 Aug 92 10:05:57 EST
  1232. Subject: THINK Pascal v4.01 and 32-bit
  1233. Organization: Australian Programming Centre (IBMA)
  1234.  
  1235. Basic Question: Is THINK Pascal v4.01 32-bit Compatible ?
  1236.  
  1237. Reason: I recently went back to THINK Pascal to try a new program
  1238. I had in mind, and had real problems getting my program to run,
  1239. after it had compiled successfully. Every time I selected a menu
  1240. THINK Pascal would give me an
  1241.     "Application Zone Damaged..." or "Bus Error"
  1242. message, and all things would slowly die (generally my system goes down).
  1243.  
  1244.  I checked all the MENU resources, checked other files and
  1245. generally got annoyed. Finally, I went to a program that used to
  1246. run without a problem from within THINK, and it also fell over. I
  1247. excluded all extensions, and only then remembered my recent switch
  1248. to 32-bit (after I purchased more memory).
  1249.  I've tried playing with the SIZE resource for my resource file, but cannot
  1250. get it to run under 32-bit memory ON. Is there something I can do,
  1251. withink THINK Pascal or elsewhere, or is the compiler just 32-bit
  1252. unfriendly (and I thought it was System 7 usable).
  1253.  
  1254.  Any suggestions, advice or words of wisdom would be more than
  1255.  welcome, and gratefully appreciated.
  1256.     Thanx
  1257.  
  1258.  
  1259. **********************************************************************
  1260. Regards,
  1261.   Michael Graf                INTERNET:    (mgraf@sydvm1.vnet.ibm.com)
  1262.                               BITNET:      (mgraf@vnet)
  1263. **********************************************************************
  1264.  
  1265. +++++++++++++++++++++++++++
  1266.  
  1267. From: siegel@world.std.com (Rich Siegel)
  1268. Date: 10 Aug 92 02:47:28 GMT
  1269. Organization: GCC Technologies
  1270.  
  1271. In article <19920809.170841.691@almaden.ibm.com> mgraf@sydvm1.VNET.IBM.COM (Michael Graf) writes:
  1272. >Basic Question: Is THINK Pascal v4.01 32-bit Compatible ?
  1273.  
  1274. Basic answer: yes.
  1275.  
  1276. There is, however, a bug with menu handling that will manifest itself
  1277. when THINK Pascal is loaded above the 16MB boundary. The problem is
  1278. fixed, and the fix will be released whenever Symantec releases the
  1279. THINK Pascal 4.0.2 patch. (I don't work there, I just know. :-])
  1280.  
  1281. In the meantime, set THINK Pascal's partition size sufficiently large
  1282. so that its application heap resides entirely below 16MB, or run some
  1283. other applications to take up the space above 16MB.
  1284.  
  1285. R.
  1286.  
  1287.  
  1288.  
  1289. - -- 
  1290. - -----------------------------------------------------------------------
  1291. Rich Siegel                              Internet: siegel@world.std.com
  1292. Software Engineer & Toolsmith
  1293. GCC Technologies
  1294.  
  1295. ---------------------------
  1296.  
  1297. End of C.S.M.P. Digest
  1298. **********************
  1299.